<!-- 
   程式: 林洵賢(Sean) 最新版本會在 http://sean.o4u.com 發佈 
   修改: Stan WU 
   081111 bug fixed, add extra URL to query Yahoo TV (advenced)
-->
<HTML>
<HEAD>
<meta http-equiv="Content-Language" content="zh-tw">
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<SCRIPT LANGUAGE="JScript">
window.moveTo(window.screen.availWidth+10,0);
</SCRIPT>
<TITLE>即時節目表&amp;選台器</TITLE>
<HTA:APPLICATION ID="tvCtrl"
APPLICATIONNAME="TV Control"
BORDER="thick"
BORDERSTYLE="normal"
INNERBORDER = "no"
CAPTION="yes"
ICON="TV16.ico"
SCROLL = "no"
SHOWINTASKBAR="yse"
SELECTION="no"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"
VERSION="2.2.0">
<STYLE TYPE="text/css"><!--
   #T {background: buttonface;border-top: 1px solid buttonhighlight;	border-left: 1px solid buttonhighlight;	border-bottom: 1px solid buttonshadow; border-right: 1px solid buttonshadow; padding: 2px; font: 12pt 新細明體;}
   #C { cursor: hand; border: 0px; }
   .tv {border: 1px solid buttonface; padding: 1px; cursor: hand;}
   .classCaption { color:captiontext; background-color:activecaption; text-align:center; font-weight:bolder; padding-top: 4px; }
   TABLE { margin:0px 0px 0px 0px; padding:0px 0px; }
   TD { font-size:9pt; }
//-->
</STYLE>
<SCRIPT LANGUAGE="JScript"><!--
var oAct,chNo,apps,rightMouseTvName;
var ActiveApp = '';
var FN = "TVControl.ini";
var CH = "Channel.ini";
var CHs = "Channels.ini";
var isInitial = false;
var isDownLoading = false;
var defaultState = '';
var activeState = defaultState;

var ini={
'width':250,
'height':300,
'enterkey':'yes',
'autodownload':'yes',
'settinghint':'yes',
'appname':'',
'appfile':'',
'appargv':'',
'key_id':777,
'key_mod':2,
'key_vk':'0x7b',
'pressdelay':10
};


var pgList,diffW,diffH,diffX,diffY;
var wX = 0;
var wY = 0;

var chYahoo = new Object();
var tvProg,tomorrowProg,nextProg,googleProg,progDay=0;

var WshShell = new ActiveXObject("WScript.Shell");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var stm = new ActiveXObject("ADODB.Stream");

checkScriptEngine();

loadIni();

loadChannels();

function loadIni() {
	if(fso.FileExists(FN)) {
		var ts = fso.OpenTextFile(FN,1);
		var s;
		var reBlock = /^\s*\[(.+)\]\s*$/i;
		var currentBlock = '';
		var preBlock = '';
		
		while(!ts.AtEndOfStream) {
			s = ts.ReadLine();
			s=s.replace(/^\s+|\s+$/g,'');
			s=s.replace(/^;.*$/,'');
			if(s=='') continue;

			if(reBlock.test(s)){
				currentBlock = RegExp.$1.toLowerCase();
				continue;
			}
			
			if(currentBlock=='option') { // ini
				if(s.search(/^\s*(.+?)\s*=\s*(.+)\s*$/) > -1)
					ini[RegExp.$1.toLowerCase()]=RegExp.$2;
			}
		}

		ts.Close();
	}
	else {
		WshShell.Popup("找不到「"+FN+"」檔案!!\n程式無法執行，即將關閉。", 10, document.title, 16);
		window.close();
	}
	
}

function checkScriptEngine() {
	var ScriptEngine = ScriptEngineMajorVersion()+"."+ScriptEngineMinorVersion();

	if( ScriptEngine < 5.6 ) {
		alert("你的 Scripting 引擎過舊 (" + ScriptEngine + " 版)，無法執行本程式。\n請至微軟網站下載更新程式。\n\n注意：Microsoft Windows Script 更新程式有分兩個不同版本，\n分別為「Windows 2000, XP」與「Windows 9x, Me, NT4」。\n請依照您的作業系統種類來更新。\n\n詳情見安裝目錄內的 readme.txt");
		window.close();
	}

}

function init() {
	//TrayCtrl.SetIcon("TVControl.ico");
	
	if(TrayCtrl.Version) {
		TrayCtrl.Contained = true;
	}
	else {
		alert("無法使用 TrayEr.ocx 元件，程式必須關閉。\n請嘗試重新安裝此程式。");
		window.close();
	}
	
	var trayMenu = ["下載節目表","顯示","編輯設定檔","說明...","","結束程式"];
	for(var i in trayMenu) {	MenuTray.AddItem(trayMenu[i]); }
	
	TrayCtrl.SetHotKey(ini['key_id'],eval(ini['key_mod']),eval(ini['key_vk']));

	pgList = document.getElementById('pgList');
	pgList.style.height = document.body.clientHeight-20;
	
	
	//--------------------------------- Menu
	var mFunc = ["立即線上更新節目表(&D)","","匯出 xmltv.xml","匯出 ChannelInfo.xml"];
	var mOpti = ["編輯設定檔(&S)","編輯頻道表(&C)","編輯頻道別名(&A)"];
	var mSite = ["Yahoo!奇摩電影(&Y)","@movies 開眼(&M)","HyTV 電視王(&H)","nio 電視娛樂網(&N)"];
	var mHelp = ["此程式首頁(&H)","關於此程式(&A)..."];
	
	for(i in mFunc) {	MenuFunction.AddItem(mFunc[i]); }
	for(i in mOpti) {	MenuOption.AddItem(mOpti[i]); }
	for(i in mSite) {	MenuSite.AddItem(mSite[i]); }
	for(i in mHelp) {	MenuHelp.AddItem(mHelp[i]); }
	
	TrayCtrl.AddMenu(MenuFunction, "功能(&F)");
	TrayCtrl.AddMenu(MenuOption, "設定(&S)");
	TrayCtrl.AddMenu(MenuSite, "網站(&W)");
	TrayCtrl.AddMenu(MenuHelp, "\\a說明(&H)");
	//---------------------------------
	
	
	

	reWindow();

   reGroup();

	isInitial = true;

	if(ini['autodownload']=='yes') downloadTvProgram();
}

function reGroup() {
   var strCloseGroup = GetCookie('CloseGroup');
   if(strCloseGroup == null) return;

   var oT = document.all.item("T");
   var i,j,capt,isClose,oTab,oImg;
   for(i=0; i<oT.length;i++){
      oTab = oT(i);
      oImg = oTab.rows(0).cells(0).children.item('C');
      capt = oTab.rows(0).cells(0).innerText;
      if(strCloseGroup.indexOf(capt)>-1) {
         oImg.src = oImg.src.replace(/-close\.png$/i, "-open.png");
         for (j=1; j<oTab.rows.length; j++) oTab.rows(j).style.display='none';
      }
   }



}

function saveGroup() {
   var oT = document.all.item("T");
   var i,capt,isClose;
   var CloseList = new Array();

   for(i=0; i<oT.length;i++){
      capt = oT(i).rows(0).cells(0).innerText;
      if(/-open\.png$/i.test(oT(i).rows(0).cells(0).children.item('C').src))
         isClose = true;
      else
         isClose = false;
      if(isClose) CloseList.push(capt);
   }

   SetCookie('CloseGroup',CloseList.join("\t"));
}

function terminate() {
   saveGroup();
   if(TrayCtrl.TaskTray == false) savePos();
}

function showWin() {
	TrayCtrl.TopMost = true;
   TrayCtrl.TaskTray = false;
	TrayCtrl.ShowRestore();
	TrayCtrl.Activate();
	TrayCtrl.TopMost = false;
}

function loadChannels() {
   var f = fso.OpenTextFile(CHs,1);
   while(!f.AtEndOfStream) {
      var v = f.ReadLine().replace(/^\s*(.+)\s*$/,"$1").split(/\s*=\s*/,2);

      if(v.length==1)
         chYahoo[v[0]] = v[0];
      else {
      	var alias = v[1].split(/\s*\,\s*/);
			for (var i in alias) chYahoo[alias[i]] = v[0];
		}
    }
    f.close();
}

function debug(s) {
	var fs, a;
	fs = new ActiveXObject("Scripting.FileSystemObject");
	a = fs.OpenTextFile("debug.txt", 8, true);
	a.Write(s+"\r\n");
	a.Close();
}

function makeFlat(el) {
	with (el.style) {
		background = "";
		border = "1px solid buttonface";
		padding = "1px";
	}
}

function makeRaised(el) {
	with (el.style) {
		borderLeft   = "1px solid buttonhighlight";
		borderRight  = "1px solid buttonshadow";
		borderTop    = "1px solid buttonhighlight";
		borderBottom = "1px solid buttonshadow";
		padding      = "1px";
	}
}

function makePressed(el) {
	with (el.style) {
		borderLeft   = "1px solid buttonshadow";
		borderRight  = "1px solid buttonhighlight";
		borderTop    = "1px solid buttonshadow";
		borderBottom = "1px solid buttonhighlight";
		paddingTop    = "2px";
		paddingLeft   = "2px";
		paddingBottom = "0px";
		paddingRight  = "0px";
		//fontWeight    = "bold";
	}
}

function sendKey() {
   var strKeys;

   var lZ = '00000'+chNo;   // Leading Zeros
   var lZ2 = lZ.substr(lZ.length-2);
   var lZ3 = lZ.substr(lZ.length-3); 

	switch(ActiveApp) {
      case 'DVD Encoder':
         strKeys = chNo.replace(/(\d)/g, "%$1");
         break;
	   case 'ComproPVR':
         strKeys = lZ3.replace(/(\d)/g, "^$1");
		   break;
		case 'ComproDTV':
         strKeys = lZ3;
		   break;
   	case 'DScaler':
   		strKeys = chNo;
   		break;
   	case 'WinFast PVR':
   	case 'InterVideo WinDVR':
         strKeys = chNo+'~';
      default: //使用者自定
   
         switch(ini['leadingzeros']) { //頻道數字碼
            case '2':
               strKeys = lZ2;
               break;
            case '3':
               strKeys = lZ3;
               break;
            default:
               strKeys = chNo;
         }
         
      if(ini['enterkey']=='yes') strKeys += '~'; // Enter 鍵
   }


   var oneKey = strKeys.match(/\^?./g);
   if(ini['pressdelay']>0) {	
      for(var i=0;i<=oneKey.index;i++) {
         if(oneKey[i]) window.setTimeout("WshShell.SendKeys('" + oneKey[i] + "')", i*ini['pressdelay']);
      }
   }
   else {
      WshShell.SendKeys(strKeys);
   }
   window.setTimeout("WshShell.AppActivate(document.title); document.focus();", oneKey.index*ini['pressdelay']+50);

}

function editIni() {
   if(ini['settinghint']=='yes') alert('編輯完成儲存後，記得重新啟動才會發生作用唷！');
   WshShell.Run('notepad '+FN);
}

function editCH() {
   if(ini['settinghint']=='yes') alert('編輯完成儲存後，記得重新啟動才會發生作用唷！');
   WshShell.Run('notepad '+CH);
}

function editCHs() {
   if(ini['settinghint']=='yes') alert('編輯完成儲存後，記得重新啟動才會發生作用唷！');
   WshShell.Run('notepad '+CHs);
}

function about() {
   window.showModalDialog("help.htm", window,"dialogHeight:260px;dialogWidth:410px;help:off;scroll:no;");
}

function google() {
   window.showModalDialog("http://m.google.com", window,"dialogHeight:260px;dialogWidth:410px;help:no;status:no;resizable:yes;scroll:yes;");
}

//下載節目表
function downloadTvProgram() {
	activeState = '節目下載中...';
   TrayCtrl.StatusText(activeState);
   isDownLoading = true;

   if(isTodayExists()) downloadComplete();

   WshShell.Run("download.wsf //nologo",0,false);
   window.setTimeout("downloadTimeout();", 30*1000);
}

function downloadTimeout() {
	activeState='';
	TrayCtrl.StatusText(activeState);
	isDownLoading=false;
	renewProg();
}

function downloadComplete() {
	isDownLoading = false;
	TrayCtrl.StatusText('節目下載完成，按滑鼠右鍵顯示全日節目表。');
	activeState = defaultState;
	renewProg();
}

function downloadFailure() {
	isDownLoading = false;
	TrayCtrl.StatusText('節目下載失敗。');
	activeState = defaultState;
	alert('節目資訊下載失敗，請稍後在嘗試下載。\n(有可能是網路連線出問題)');
}

//取得事件上的上幾層是否是 tv class
function getTVElement(o) {
   for(var i=0;i<5;i++){
      if(o.className == 'tv') break;
      o = o.parentElement;
      if(o==null) break;
   }
   if(o)
      if(o.className != 'tv')
         o = null;
   return(o);
}

function timeString(sec) {
	if(sec<0) sec+= 3600*24;
	var hh = '0'+Math.floor(sec/3600);
	var mm = '0'+Math.floor((sec-(hh*3600))/60);
   hh = hh.substr(hh.length-2);
	mm = mm.substr(mm.length-2);
	return(hh+':'+mm);
}

function getNowProg(tvName) {
   var d,nowSec,nowProg,afterMinutes;
   nowProg = '';
   
   if(tvProg[tvName]) {
      d = new Date();
      nowSec = d.getHours()*3600 + d.getMinutes() * 60 + d.getSeconds();
      for(i=0;i<tvProg[tvName].length;i++) {
         if(nowSec>=tvProg[tvName][i][0]){
         	nowProg = tvProg[tvName][i][1];
         	googleProg[tvName] = nowProg;
         	 		
				if(i+1==tvProg[tvName].length) 
					nextProg[tvName] = '';
				else {
					afterMinutes = Math.floor((tvProg[tvName][i+1][0]-nowSec)/60);
					
					if(afterMinutes==0)
						nextProg[tvName] = '即將播放：' + tvProg[tvName][i+1][1].replace(/\t/,' ');
					else
						nextProg[tvName] = '再過 '+ afterMinutes +' 分鐘：' + tvProg[tvName][i+1][1].replace(/\t/,' ');
				}
				
        	}
      }
   }
   else {
      return('');
   }
   return(nowProg);
}

function isTodayExists() { // 今日資料是否存在
   var d = new Date();
   var yy = d.getFullYear();
   var mm = d.getMonth()+1;
   var dd = d.getDate();
   yy = yy.toString();
   if(mm<10) mm = ('0'+mm).toString();
   else mm = mm.toString();
   if(dd<10) dd = ('0'+dd).toString();
   else dd = dd.toString();
   
   return(fso.FileExists('data\\'+yy+mm+dd+'.txt'));
}

function loadTvProg() {
   

   var d = new Date();
   var yy = d.getFullYear();
   var mm = d.getMonth()+1;
   var dd = d.getDate();
   yy = yy.toString();
   if(mm<10) mm = ('0'+mm).toString();
   else mm = mm.toString();
   if(dd<10) dd = ('0'+dd).toString();
   else dd = dd.toString();

	if(progDay==dd) return; //已經開檔過
   
	tvProg = getFromFile('data\\'+yy+mm+dd+'.txt');
	progDay = (tvProg==null)?0:dd;


	d = new Date(d.getTime() + 86400000); //24小時後
   yy = d.getFullYear();
   mm = d.getMonth()+1;
   dd = d.getDate();
   yy = yy.toString();
   if(mm<10) mm = ('0'+mm).toString();
   else mm = mm.toString();
   if(dd<10) dd = ('0'+dd).toString();
   else dd = dd.toString();

	tomorrowProg = getFromFile('data\\'+yy+mm+dd+'.txt');

}

function getFromFile(fn) {

	if(!fso.FileExists(fn)) return(null);
	
	var oProg = new Object();
   var re = /^(\d{2}):(\d{2})\t(.+)$/;

	var str='';
	var currentTV='';
	stm.Type = 2;				//adTypeText
	stm.Charset = "utf-8";
	stm.Open();
	stm.LoadFromFile(fn);
	
	
	while(!stm.EOS) {
		str = stm.ReadText(-2); //adReadLine
		
      if(str.indexOf("\t")==0) {
         currentTV = str.substr(1);
         oProg[currentTV] = new Array();
         continue;
      }
      
      if(re.test(str)) {
      	var pgHH = Math.floor(RegExp.$1);
      	var pgMM = Math.floor(RegExp.$2);
      	if(oProg[currentTV].length==0 && pgHH>=12) pgHH-=24; //跨日節目
         oProg[currentTV].push( new Array(pgHH*3600+pgMM*60,RegExp.$3) );
		}

	}
   stm.Close();
   return(oProg);
	
}

function renewProg() {
   var i,j,chName;
   loadTvProg();
   nextProg = new Object();
   googleProg = new Object();
   
   if(tvProg == null) return(0);
   
   for(i=0;i<document.all.T.length;i++) {
      for(j=0;j<document.all.T[i].rows.length;j++) {
         if(document.all.T[i].rows[j].cells.length ==2 && !isNaN(document.all.T[i].rows[j].cells[0].innerText) ) {
            chName = document.all.T[i].rows[j].cells[1].children[0].rows[0].cells[0].innerText;
            
            if(chYahoo[chName]) chName = chYahoo[chName]; //改成頻道ID

            if(tvProg[chName]) {
               document.all.T[i].rows[j].cells[1].children[0].rows[0].cells[1].innerHTML = prog2HTML(getNowProg(chName));
            }

         }
      }
   }
   
   return(1);
}

function prog2HTML(s) {
   s = s.replace(/^(.*)(【.+】)(.+)\t(.*)$/,'$1$3\t$2$4');
   s = s.replace(/\t(.+)$/,' <wbr><span style="color:gray">$1</span>');
   return(s);
}

function checkRenew() {
   var d = new Date();
   if(d.getSeconds() == 0) {
      renewProg();
   }

   if(TrayCtrl.TaskTray == false) {
      if(wX != window.screenLeft) {
         wX = window.screenLeft;
         SetCookie('posX',wX-diffX);
      }
      if(wY != window.screenTop) {
         wY = window.screenTop;
         SetCookie('posY',wY-diffY);
      }
   }
}

function savePos() {
   //記錄位置
   SetCookie('posX',window.screenLeft-diffX);
   SetCookie('posY',window.screenTop-diffY);
}

function reWindow() {
   //復原視窗位置及大小

   diffX = window.screenLeft-(window.screen.availWidth+10);
   diffY = window.screenTop;
   
   window.resizeTo(200,200);
   diffW = 200-document.body.clientWidth;
   diffH = 200-document.body.clientHeight;

   var posX = GetCookie('posX');
   var posY = GetCookie('posY');
   var winW = GetCookie('winW');
   var winH = GetCookie('winH')-19;

   if(isNaN(winW) || isNaN(winH))
      window.resizeTo(300,400);
   else
   	if(winW<10||winH<10)
   		window.resizeTo(300,400);
   	else
      	window.resizeTo(winW,winH);

   if(isNaN(posX) || isNaN(posY)) {
      posX = 200;
      posY = 50;
   }

   if( posX>window.screen.availWidth || posX<0 ) { posX = 200; }
   
   if( posY>window.screen.availHeight || posY<0)  { posY = 50; }

   window.moveTo(posX,posY);
}

function SetCookie(sName, sValue) {
   var today = new Date();
   var expires = new Date();
   expires.setTime(today.getTime() + 1000*60*60*24*365);
   document.cookie = sName + "=" + escape(sValue) + "; expires=" + expires.toGMTString();
}

function GetCookie(sName) {
   var aCookie = document.cookie.split("; ");
   for (var i=0; i < aCookie.length; i++) {
      var aCrumb = aCookie[i].split("=");
      if (sName == aCrumb[0])
         return unescape(aCrumb[1]);
   }
   return null;
}

function execAppFile() {
   if(fso.FileExists(FN))
      WshShell.Run('"'+ini['appfile']+'" '+ini['appargv']);
   else
      WshShell.Popup("您在設定檔指定的檔案路徑不存在。\n("+ini['appfile']+")", 0, document.title, 48);
}

//選台
function changeCh(eventSrc) {
   var o = getTVElement(eventSrc);
   var js,i;
   if(o) {
      if(o.attributes.getNamedItem('JS'))
      	js = o.attributes.getNamedItem('JS').value;

      if(js)
         eval(js);      
      else {
         makeRaised(o);
         o.children[0].rows[0].cells[0].style.fontWeight = "bold";
         if(oAct)
            if(oAct != o)
               oAct.style.fontWeight = "normal";
         oAct = o.children[0].rows[0].cells[0];
         
         /// 選台
         chNo = o.parentElement.cells(0).innerText;

         // 決定 AP 名稱
         if(ActiveApp == '') {
            for (i in apps)   {
               if(WshShell.AppActivate(apps[i])) {
                  ActiveApp = apps[i];
                  break;
               }
            }
         }

         if(ActiveApp == '') {
            if(ini['appfile']) {
               if(ini['appfile'].toLowerCase()=="none")
                  viewAllday(eventSrc);
               else
                  if(WshShell.Popup("沒有發現電視播放程式，是否要幫您啟動?\n\n按 [是] 即將執行下列指令:\n"+ini['appfile'], 0, document.title, 4+32)==6)
                     execAppFile();
            }
            else
               alert("請開啟您的電視播放程式才能轉台。\n\n如果您第一次使用請點選 [設定] 選單來設定您的電視軟體。\n更多使用方法參見 [說明] 選單。");
         }
         else {
            if(WshShell.AppActivate(ActiveApp))
            	window.setTimeout("sendKey()", 50);
            else {
               if(WshShell.Popup("電視播放程式關閉時無法轉台，是否要幫您啟動?\n\n按 [是] 即將執行下列指令:\n"+ini['appfile'], 0, document.title, 4+32)==6)
                  execAppFile();
            }
         }
      }

   }
}

//整日節目表
function viewAllday(eventSrc) {
	var o = getTVElement(eventSrc);
	 if(o) {
	 	if(o.children[0]) {
	 		rightMouseTvName = o.children[0].rows[0].cells[0].innerText;
			window.showModalDialog("list.htm",window,"dialogHeight:400px; dialogWidth:300px; center:yes; help:no; status:no; resizable:yes; scroll:yes;");
		}
	}
}

function doExit() {
	return(window.confirm("確定結束此程式?"));
}

window.onbeforunload = doExit;

//-->
</SCRIPT>
<SCRIPT LANGUAGE="JScript" FOR="C" EVENT="onclick">
var oImg=event.srcElement;
if(oImg.tagName=='IMG') {
   var oTab = oImg.parentElement.parentElement.parentElement.parentElement;

   if(/-close\.png$/i.test(oImg.src)) { //執行縮起來
      oImg.src = oImg.src.replace(/-close\.png$/i, "-open.png");
      for (var i=1; i<oTab.rows.length; i++) oTab.rows(i).style.display='none';
   }
   else {//執行打開
      oImg.src = oImg.src.replace(/-open\.png$/i, "-close.png");
      for (var i=1; i<oTab.rows.length; i++) oTab.rows(i).style.display='';
   }
}
</SCRIPT>
<SCRIPT LANGUAGE="JScript" FOR="T" EVENT="onmouseover">
	var tvAlias,tvID,strNextPg;
   var o = getTVElement(event.srcElement);

	var ststusText = activeState;

	if(isDownLoading==false) {
	   if(o){
			makeRaised(o);
			if(o.children[0]) {
				tvAlias = o.children[0].rows[0].cells[0].innerText;
		 		if(chYahoo[tvAlias] && nextProg != null) {
		 			strNextPg = nextProg[chYahoo[tvAlias]];
		 			if(strNextPg) ststusText = strNextPg;
		 		}
			}
		}
	}

	if(TrayCtrl)
		TrayCtrl.StatusText(ststusText);
</SCRIPT>
<SCRIPT LANGUAGE="JScript" FOR="T" EVENT="onmouseout">
   var o = getTVElement(event.srcElement);
   if(o) makeFlat(o);
   
   if(isDownLoading==false) {
		if(TrayCtrl) TrayCtrl.StatusText('');
   }
</SCRIPT>
<SCRIPT LANGUAGE="JScript" FOR="T" EVENT="onmousedown">
   var o = getTVElement(event.srcElement);
   if(o) makePressed(o);
</SCRIPT>
<SCRIPT LANGUAGE="JScript" FOR="T" EVENT="onmouseup">
	
	switch(event.button) {
		case 1: //左鍵
			changeCh(event.srcElement);
			break;
		case 2: //右鍵
			viewAllday(event.srcElement);
			break;
	}
</SCRIPT>
<script language="JScript" FOR="TrayCtrl" EVENT="OnClick(x,y)">
   showWin();
</script>
<SCRIPT LANGUAGE="JScript" FOR="TrayCtrl" EVENT="OnSize(windowState)">
	switch (windowState) {
		case 1:
			TrayCtrl.TaskTray = true;
			break;
	}
</SCRIPT>
<SCRIPT LANGUAGE="JScript" FOR="TrayCtrl" EVENT="OnRightClick(x,y)">
	window.MenuTray.PopupS(x, y);
</SCRIPT>
<SCRIPT LANGUAGE="JScript" for="TrayCtrl" event="OnHotKey()">
   TrayCtrl.ShowRestore();
   TrayCtrl.Activate();
	WshShell.AppActivate(document.title);
	document.focus();
</SCRIPT>
<SCRIPT LANGUAGE="JScript" FOR="MenuFunction" EVENT="OnClick(no)">
	switch(no) {
		case 0: //下載
			downloadTvProgram();
			break;
		case 2: //XMLTV
			WshShell.Run("ExportXmltv.wsf //nologo",0,false);
			break;
		case 3: //ChannelInfo
			WshShell.Run("ExportChannelInfo.wsf //nologo",0,false);
			break;
	}
</SCRIPT>
<SCRIPT LANGUAGE="JScript" FOR="MenuOption" EVENT="OnClick(no)">
	switch(no) {
		case 0: //設定
			editIni();
			break;
		case 1: //頻道
			editCH();
			break;
		case 2: //別名
			editCHs();
			break;
	}
</SCRIPT>
<SCRIPT LANGUAGE="JScript" FOR="MenuSite" EVENT="OnClick(no)">
	switch(no) {
		case 0:
			window.open("http://tw.movie.yahoo.com/tv_index.html","_blank");
			break;
		case 1:
			window.open("http://www.atmovies.com.tw/home/tv_homepage.html","_blank");
			break;
		case 2:
			window.open("http://www.hytv.com.tw/","_blank");
			break;
		case 3:
			window.open("http://www.niotv.com/","_blank");
			break;
	}
</SCRIPT>
<SCRIPT LANGUAGE="JScript" FOR="MenuHelp" EVENT="OnClick(no)">
	switch(no) {
		case 0:
			window.open("http://sean.o4u.com","_blank");
			break;
		case 1:
			about();
			break;
	}
</SCRIPT>
<SCRIPT LANGUAGE="JScript" FOR="MenuTray" EVENT="OnClick(no)">
	switch (no) {
		case 0:
		   downloadTvProgram();
			break;
		case 1:
		   showWin();
			break;
		case 2:
		   editIni();
			break;
		case 3:
		   about();
			break;
      case 5:
		   window.close();
			break;
	}
</SCRIPT>
<SCRIPT LANGUAGE="JScript" FOR="window" EVENT="onresize">
	if(isInitial) {
		pgList.style.height = document.body.clientHeight-20;
	   SetCookie('winW',document.body.clientWidth+diffW);
	   SetCookie('winH',document.body.clientHeight+diffH);
	}
</SCRIPT>
<SCRIPT LANGUAGE="JScript" FOR="document" EVENT="onkeypress">
	var k = event.keyCode;
	if(k==40) downloadFailure(); //按鍵 '('
	if(k==41) downloadComplete(); //按鍵 ')'
</SCRIPT>


</HEAD>
<BODY bgcolor="buttonface" LEFTMARGIN=0 RIGHTMARGIN=0 TOPMARGIN=0 onload="init()" onbeforeunload="terminate()">
<DIV ID="pgList" STYLE="width:100%; height:100%; overflow-x:hidden;overflow-y:auto;">
<SCRIPT LANGUAGE="JScript">
<!--
if(fso.FileExists(CH)) {
	var ts = fso.OpenTextFile(CH,1);
	var s;
	var reBlock = /^\s*\[(.+)\]\s*$/i;
	var currentBlock = '';
	var preBlock = '';
	
	while(!ts.AtEndOfStream) {
		s = ts.ReadLine();
		s=s.replace(/^\s+|\s+$/g,'');
		s=s.replace(/^;.*$/,'');
		if(s=='') continue;
		
		if(reBlock.test(s)){
			currentBlock = RegExp.$1.toLowerCase();
			
			if(currentBlock!='option'){ // new type
				//End CH Type
				if(preBlock!=''&&preBlock!=currentBlock) document.write('</table>');
				
				//Start CH Type
				document.write('<table ID=T border=0 width=100%><tr><td colspan=2 class="classCaption"><img id=C src="switch-close.png" width=9 height=9 align="right">'+currentBlock+'</td></tr>');
			   preBlock=currentBlock;
			}
			continue;
		}

		if(s.search(/^\s*(\d+)\s+(.+)\s*$/) > -1)
			document.write('<tr><td width=16>'+RegExp.$1+'</td><td class=tv><table border=0 cellpadding=0 cellspacing=0 width=100% height=16><tr><td width=80>'+RegExp.$2+'</td><td style="color:darkblue;">&nbsp;</td></table></td></tr>\n');

	}
	
	//End CH Type
	if(currentBlock!='option')
		document.write('</table>');
	
	ts.Close();

}
else {
	WshShell.Popup("找不到「"+CH+"」檔案!!\n程式無法執行，即將關閉。", 10, document.title, 16);
	window.close();
}

if(ini['appname']=='' || ini['appname'].indexOf('(') == 0 ) {
	if(WshShell.Popup("找不到「"+FN+"」檔案中的 AppName 參數。\n你是否要現在開啟設定檔來編輯?",30, document.title, 1+32) == 1)
        editIni();
    window.close();
}

apps = ini['appname'].split("|");

ini['enterkey'] = ini['enterkey'].toLowerCase();
ini['autodownload'] = ini['autodownload'].toLowerCase();
ini['settinghint'] = ini['settinghint'].toLowerCase();

var renewTID = window.setInterval("checkRenew()",1000);
//-->
</SCRIPT>
</DIV>
<object id="TrayCtrl" classid="CLSID:B0000301-BFDE-11D3-981C-00004CAD9063" CODEBASE="TrayEr.ocx" WIDTH=0 HEIGHT=0>
<PARAM NAME="Tip" VALUE="即時節目表＆選台器">
<PARAM NAME="TaskTray" VALUE="false">
<PARAM NAME="RightClick" VALUE="false">
<PARAM NAME="StatusVisible" VALUE="true"></object>
<OBJECT ID='MenuTray' CLASSID='CLSID:B0000351-BFDE-11D3-981C-00004CAD9063' WIDTH=0 HEIGHT=0></OBJECT>
<OBJECT ID='MenuFunction' CLASSID='CLSID:B0000351-BFDE-11D3-981C-00004CAD9063' WIDTH=0 HEIGHT=0></OBJECT>
<OBJECT ID='MenuOption' CLASSID='CLSID:B0000351-BFDE-11D3-981C-00004CAD9063' WIDTH=0 HEIGHT=0></OBJECT>
<OBJECT ID='MenuSite' CLASSID='CLSID:B0000351-BFDE-11D3-981C-00004CAD9063' WIDTH=0 HEIGHT=0></OBJECT>
<OBJECT ID='MenuHelp' CLASSID='CLSID:B0000351-BFDE-11D3-981C-00004CAD9063' WIDTH=0 HEIGHT=0></OBJECT>
</BODY>
</HTML>
